home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / var / lib / dpkg / info / grub-pc.postinst < prev    next >
Text File  |  2009-10-29  |  4KB  |  131 lines

  1. #!/bin/bash -e
  2.  
  3. merge_debconf_into_conf()
  4. {
  5.   local tmpfile; tmpfile="$1"
  6.   local setting; setting="$2"
  7.   local template; template="$3"
  8.  
  9.   db_get "$template"
  10.   local value; value="$(echo "$RET" | sed -e 's,[$`"\],\\&,g; s,[\@],\\&,g')"
  11.   if grep -q "^${setting}=" "$tmpfile"; then
  12.     sed -i -re "s@^(${setting}=).*@\1\"${value}\"@" "$tmpfile"
  13.   else
  14.     echo >> "$tmpfile"
  15.     echo "${setting}=\"${value}\"" >> "$tmpfile"
  16.   fi
  17. }
  18.  
  19. case "$1" in
  20.   configure)
  21.     . /usr/share/debconf/confmodule
  22.  
  23.     case grub-pc in
  24.       grub-pc)
  25.  
  26.         if grep -q "[= ]/sbin/update-grub" /etc/kernel-img.conf 2> /dev/null ; then
  27.           echo -e "\n/etc/kernel-img.conf still contains /sbin/update-grub in the hooks." >&2
  28.           echo -e "Running sed over it to remove the /sbin/ prefix.\n" >&2
  29.           sed -i /etc/kernel-img.conf -e "s,\(.*\)  */sbin/update-grub$,\1 update-grub,g"
  30.         fi
  31.         mkdir -p /boot/grub
  32.  
  33.         if test -e /boot/grub/device.map && ! test -e /boot/grub/core.img ; then
  34.           # Looks like your device.map was generated by GRUB Legacy, which
  35.           # used to generate broken device.map (see #422851).  Avoid the risk
  36.           # by regenerating it.
  37.           grub-mkdevicemap --no-floppy
  38.         fi
  39.       ;;
  40.     esac
  41.  
  42.     tmp_default_grub="$(mktemp "/tmp/grub.XXXXXXXXXX")"
  43.     trap "rm -f ${tmp_default_grub}" EXIT
  44.     cp -p /usr/share/grub/default/grub ${tmp_default_grub}
  45.  
  46.     merge_debconf_into_conf "$tmp_default_grub" GRUB_CMDLINE_LINUX grub2/linux_cmdline
  47.     merge_debconf_into_conf "$tmp_default_grub" GRUB_CMDLINE_LINUX_DEFAULT grub2/linux_cmdline_default
  48.  
  49.     case grub-pc in
  50.       grub-pc)
  51.         merge_debconf_into_conf "$tmp_default_grub" GRUB_TIMEOUT grub-pc/timeout
  52.         db_get grub-pc/hidden_timeout
  53.         if [ "$RET" = false ]; then
  54.           sed -i -e 's/^GRUB_HIDDEN_TIMEOUT=/#&/' "$tmp_default_grub"
  55.         fi
  56.       ;;
  57.     esac
  58.  
  59.     ucf --three-way --debconf-ok --sum-file=/usr/share/grub/default/grub.md5sum ${tmp_default_grub} /etc/default/grub
  60.     package="$(ucfq --with-colons /etc/default/grub | cut -d : -f 2)"
  61.     if echo $package | grep -q "^grub-" ; then
  62.       ucfr --force grub-pc /etc/default/grub
  63.     else
  64.       ucfr grub-pc /etc/default/grub
  65.     fi
  66.  
  67.     case grub-pc in
  68.       grub-pc)
  69.  
  70.         if test -e /boot/grub/stage2 && test -e /boot/grub/menu.lst && ! test -e /boot/grub/core.img ; then
  71.           db_get grub-pc/chainload_from_menu.lst
  72.           if $RET ; then
  73.             # Create core.img (but do not risk writing to MBR).
  74.             echo "Generating core.img" >&2
  75.             grub-install --no-floppy --grub-setup=/bin/true "(hd0)" > /dev/null
  76.  
  77.             # Update menu.lst to reflect that:
  78.             # - core.img is present now
  79.             # - core.img has to be the first option
  80.             echo "Saving menu.lst backup in /boot/grub/menu.lst_backup_by_grub2_postinst" >&2
  81.             cp /boot/grub/menu.lst{,_backup_by_grub2_postinst}
  82.             echo "Running update-grub Legacy to hook our core.img in it" >&2
  83.             LET_US_TRY_GRUB_2=true /usr/lib/grub-legacy/update-grub 2>&1 | sed -e "s/^/    /g" >&2
  84.             # We just hooked GRUB 2 in menu.lst; then also generate grub.cfg.
  85.             touch /boot/grub/grub.cfg
  86.           fi
  87.         else
  88.           db_subst grub-pc/install_devices CHOICES `grub-mkdevicemap -m - | sed -e "/^(fd[0-9]\+)/d;s,.*\t,,g" | tr '\n' ',' | sed -e 's/,$//g;s/,/, /g'`
  89.           db_input high grub-pc/install_devices || true
  90.           db_go
  91.           db_get grub-pc/install_devices
  92.           for i in `echo $RET | sed -e 's/,/ /g'` ; do
  93.             if grub-install --no-floppy $i ; then
  94.               # We just installed GRUB 2; then also generate grub.cfg.
  95.               touch /boot/grub/grub.cfg
  96.             fi
  97.           done
  98.         fi
  99.  
  100.         # /boot/grub/ has more chances of being accessible by GRUB
  101.         if test -e /boot/grub/grub.cfg ; then
  102.           for i in /usr/share/grub/unicode.pf2 /usr/share/images/desktop-base/moreblue-orbit-grub.png ; do
  103.             if test -e $i ; then
  104.               cp $i /boot/grub/
  105.             fi
  106.           done
  107.         fi
  108.  
  109.       ;;
  110.     esac
  111.  
  112.     # If grub.cfg has been generated, update it.
  113.     if test -e /boot/grub/grub.cfg ; then
  114.       update-grub
  115.     fi
  116.   ;;
  117.   abort-upgrade|abort-remove|abort-deconfigure)
  118.   ;;
  119.   *)
  120.     echo "postinst called with unknown argument \`$1'" >&2
  121.     exit 1
  122.   ;;
  123. esac
  124.  
  125. # dh_installdeb will replace this with shell code automatically
  126. # generated by other debhelper scripts.
  127.  
  128.  
  129.  
  130. exit 0
  131.